package org.example.likou150.array;

/*
* https://leetcode.cn/problems/rotate-array/?envType=study-plan-v2&envId=top-interview-150
* */
public class Rotate {
    public static void main(String[] args) {
        int[] nums = new int[]{1,2};
        int k = 3;
        Rotate rotate = new Rotate();
        rotate.rotate(nums, k);
    }

    public void rotate(int[] nums, int k) {
        k= k % nums.length;
        int[] temp = new int[k];
        System.arraycopy(nums, nums.length-k, temp, 0, k);
        System.arraycopy(nums, 0, nums, k, nums.length-k);
        System.arraycopy(temp, 0, nums, 0, k);

        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }
}
